﻿@using MyWebProject.Models.Entity;
<div>
    <ul class="list-inline" style="margin-bottom:5px"></ul>
</div>
<table class="table table-hover table-condensed">
    <thead>
        <tr>
            <th style="max-width:200px">
                <a class="label label-default" onclick="selectAll()" href="javascript:void(0)">全选</a>
            </th>
            <th>昵称</th>
            <th>权限</th>
            <th>过期</th>
            <th>GitHubId</th>
            <th>QQid</th>
            <th>GitHub账号</th>
            <th>
                <a class="label label-success" onclick="add()" href="javascript:void(0)">新增</a>
                <a class="label label-danger" onclick="delAll()" href="javascript:void(0)">批量删除</a>
            </th>
        </tr>
    </thead>
    <tbody>
        @{List<USER_INFO> list = Model as List<USER_INFO>;
            foreach (USER_INFO u in list)
            {
                <tr id="cfg_@u.USER_ID">
                    <td><input style="width:30px" id="check_@u.USER_ID" type="checkbox" class="checkbox" /></td>
                    <td><input style="width:120px" id="NICK_NAME_@u.USER_ID" class="input-sm" type="text" value="@u.NICK_NAME" disabled="disabled" /></td>
                    <td><input style="width:50px" id="USER_AUTH_@u.USER_ID" class="input-sm" type="text" value="@u.USER_AUTH" disabled="disabled" /></td>
                    <td><input style="width:150px" id="EXPIRE_TIME_@u.USER_ID" class="input-sm" type="text" value="@u.EXPIRE_TIME" disabled="disabled" /></td>
                    <td><input style="width:100px" id="GITHUB_ID_@u.USER_ID" class="input-sm" type="text" value="@u.GITHUB_ID" disabled="disabled" /></td>
                    <td><input style="width:100px" id="QQ_ID_@u.USER_ID" class="input-sm" type="text" value="@u.QQ_ID" disabled="disabled" /></td>
                    <td><input style="width:150px" id="GITHUB_LOG_IN_ACCOUNT_@u.USER_ID" class="input-sm" type="text" value="@u.GITHUB_LOG_IN_ACCOUNT" disabled="disabled" /></td>
                    <td>
                        <a class="label label-warning" data-toggle="modal" onclick="mod(@u.USER_ID)" data-target="#myModal">
                            修改
                        </a>
                        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"></div>
                        <a style="margin-left:5px" class="label label-danger" href="javascript:void(0)" onclick="del(@u.USER_ID,true)">删除</a>
                    </td>
                </tr>}
        }
    </tbody>
</table>
<input id="tempSerial" value="1" style="visibility:collapse" />

<script>
    function mod(userId) {
        //$('#myModal').modal('show');
        //var location = (window.location + '').split('/');
        //var basePath = location[0] + '//' + location[2] + '/' + location[3];
        //alert(basePath);
        //$("#myModal").modal({
        //    remote: basePath+"Modal.cshtml",//可以填写一个url，会调用jquery load方法加载数据
        //    backdrop: "static",//指定一个静态背景，当用户点击背景处，modal界面不会消失
        //    s
        //    keyboard: true//当按下esc键时，modal框消失
        //});
        $('#myModal').children().remove();
        $.post('Management/ModUserInfo', { "userId": userId }, function (data) {
            $('#myModal').append(data);
            $('#myModal').modal('show');
        });

        //if ($("#check_" + id).prop("checked") == true) {
        //    $("#check_" + id).prop("checked", false);
        //    $("#key_" + id).prop("disabled", true);
        //    $("#val_" + id).prop("disabled", true);
        //    $("#mod_" + id).html("修改");
        //    return;
        //}
        //$("#key_" + id).prop("disabled", false);
        //$("#val_" + id).prop("disabled", false);
        //$("#check_" + id).prop("checked", true);
        //$("#mod_" + id).html("取消修改");
    }
    function delAll() {
        if (!window.confirm("全部删除?")) {
            return;
        }
        var str = "";
        $(".checkbox").each(function () {
            if ($(this).prop("checked") == true) {
                str += $(this).attr("id").split('_')[1] + ',';
                del($(this).attr("id").split('_')[1], false);
            }
        });
        str = str.substr(0, str.length - 1);
    }
    function del(id, flag) {
        if (flag == true || flag == 'true') {
            if (!window.confirm("确认删除?")) {
                return;
            }
        }
        $.post("Management/UserDel?userId=" + id, function (data) {
            if (data != "success") {
                alert("保存失败!");
                return;
            }
            selectMenu($("#menuId").val());
            $("#cfg_" + id).remove();
        });
    }
    function add() {
        $('#myModal').children().remove();
        $.post('Management/AddUserInfo', function (data) {
            $('#myModal').append(data);
            $('#myModal').modal('show');
        });
    }
    function selectAll() {
        //新版本JQUERY用attr设置true/false有问题,改用prop
        if ($(".checkbox").prop("checked") == true) {
            $(".checkbox").prop("checked", false);
            return;
        }
        $(".checkbox").prop("checked", true);
    }
</script>
